<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page session="true"%>
<%@page import="com.webapp.model.User"%>
<%@page import="com.webapp.model.Application,java.util.Vector,com.webapp.model.Review;" %>
<%
	User user = (User) session.getAttribute("UserObject");
	if (user != null)
		System.out.println(user.getUserName());

	Application app = (Application) session.getAttribute("Application");
	
	Review review = (Review)session.getAttribute("Review");
	
	System.out.println(review);
%>




<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Applicant's 'Application</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<style type="text/css">
			body { font-size: 95%; font-family: 'Open Sans'; padding:0; margin:0; background-color:#fff;}
			h1 { padding:0; margin:0; }
			h2 { padding:0; margin:0; }
			.sign_on_btn { background-color: #CC0000; color: #fff; border: 1px solid #990000; padding: 5px; cursor:pointer!important;}
			.sign_on_btn:hover { background-color:red; }
			.txtbox { background-color:#fff; border: 1px solid #ccc; width: 30px; }<br />
			.txtbox:focus { border: 1px soild #CC0000; }
			a { color: blue; }
			#top_of_site { padding: 5px;color: #333; background-color: #333; color:#fff; border: 1px solid #000;}
			#top_of_site h1 { padding:0; margin:0; font-size: 90%; }
			#wrapper { padding: 15px; }
			#login { width: 300px; margin: 0px auto 0px auto; padding: 10px;background-color: #333; color:#fff; border: 1px solid #000; }
			#info_bar { text-align:right; }
			#menu_container { width: 560px; margin: 30px auto 0px auto;  overflow:auto;}
			#behaviorcontainer { float:left; width: 400px; overflow:auto; }
			#extra_info { width: 560px; margin: 30px auto 0px auto;}
			#menu_container a { text-decoration: none; color: #fff; }
			#logout { float:left; background-color:#f2f2f2; border: 1px solid #ccc; color:#333; width: 100px; padding: 59px 15px 59px 15px; margin: 5px; }
			#viewTable { background-color:#0066CC; border: 1px solid #0066FF; width: 350px; padding: 20px; margin: 5px; }
			#submitApp { background-color:#B22222; border: 1px solid #990000; width: 350px; padding: 20px; margin: 5px; } 
			#apptable td { padding: 5px; }
			.even { background-color:#fff; padding:10px; cursor:pointer!important; }
			.odd { background-color:#ccc; padding:10px;cursor:pointer!important; }
			.even:hover { background-color: #0066CC; color: #fff; cursor:pointer!important; }
			.odd:hover { background-color: #0066CC; color:#fff;cursor:pointer!important;  }
			
			.form { font-size: 15px; margin-left:auto; margin-right:auto; width:10%; background-color:#b0e0e6;}
			.okay_button{font-size: 20px; margin-left:auto; margin-right:auto; width:10%; background-color:#b0e0e6;}
			.menu_button { display:inline-block;}
			.menu-button-right { position:relative; display:block; float:right; }
			.btn { background-color: #CC0000; color: #fff; border: 1px solid #990000; padding: 5px; cursor:pointer!important;}
			.btn:hover { background-color:red; }
</style>

<script language="javascript" type="text/javascript">
     function divoutSummary(ctl){
        var code=ctl.innerText;
        holdtext1.innerText=code;
        Copied = holdtext1.createTextRange();
        Copied.execCommand('Copy');
        return false;
    }
    
    function divoutTOELF(ct2)
    {
        var code=ct2.innerText;
        holdtext2.innerText=code;
        Copied = holdtext2.createTextRange();
        Copied.execCommand('Copy');
        return false;
    }
    
    function enableFields()
    {
    	if (document.review.edit_chkBox.checked)
    	{
    		document.review.desired_reviews.disabled=false;
    		document.review.tier.disabled=false;
    		document.review.text_summary.disabled=false;
    		document.review.text_comment.disabled=false;
    		document.review.update.disabled=false;
    	} else {
    		document.review.desired_reviews.disabled=true;
    		document.review.tier.disabled=true;
    		document.review.text_summary.disabled=true;
    		document.review.text_comment.disabled=true;
    		document.review.update.disabled=true;
    	}
    }
    
    function validateFields()
    {
    	
    }
</script>
</head>

<body>
	<div id="top_of_site">
		<h1>Graduate Application Review System (GARS)</h1>
	</div>

	<div id="wrapper">
		<form name="return" action="homepage.jsp" method="get">
					<!-- Returns to the previous page, which would be the view table page.-->
					<input type="submit" value="Goto Applications Table" class="btn">
				</form>
		<div id="info_bar">
			<p style="padding:0; margin:0;">Welcome, <strong><%= user.getUserName() %></strong>! You are a <strong><%= user.getType()  %></strong> member! </p>
           <p> You have <strong><%= user.getReviews()%></strong> reviews waiting to be reviewed! <br/><a href="ViewUserApp.do">Review Now!</a></p>
		</div>

		<div id="content">
			<h1>Application Information</h1>
			<h3>(Last Updated: <%=app.getUploadDate()%>)</h3>
		
			<!-- Represents basic information about the applicant -->
			<div id="user_general_info">
				<hr/>
					<h3>
						<u>Applicant's General Information</u>
					</h3>
				<table border="0" width="1100" cellpadding="3" cellspacing="3">
					<tr>
						<td><b>Applicant's Name:</b>
						<i><%=app.getFirstName() + " " + app.getMiddleName() + " " + app.getLastName()%></i>
						</td>
						
						<td><b>Applicant's E-Mail:</b>
						<i><%=app.getEmail()%></i>
						</td>
						
					</tr>

					<tr>
						<td><b>Applicant's Stony Brook ID:</b>
						<i><%=app.getSbuId()%></i>
						</td>

						<td><b>Applicant's Stony Brook GPA:</b>
						<i><%=app.getSbuGpa()%></i>
						</td>
						

						<td><b>Applicant's Degree Program:</b>
						<i><%=app.getDegreeProgram()%></i>
						</td>
					</tr>

					<tr>
						<td><b>PDF File:</b>
					
						<i><%=app.getFirstName() + "'s PDF"%></i>
					
						</td>
						
						<td><b>AY File:</b>
						<a href="viewSingleAppsTestAY.jsp">
						<i><%=app.getFirstName() + "'s AY"%></i>
						</a>
						</td>
						
						<td><b>OTS File:</b>
						<a href="viewSingleAppsTestOTS.jsp">
						<i><%=app.getFirstName() + "'s OTS"%></i>
						</a>
						</td>
					</tr>
				</table>
				<br/>
					<hr/>
			</div>
		
		<!-- Represents review information about the application -->
		<div id="review_info" >
				
				<h3>
					<u>Application's Review Information</u>
				</h3>
				
				<form id="review" name="review" action="EditApp.do" method="post">
				<table border="0" width="1200" cellpadding="3" cellspacing="3">
					<tr>
						<td>
						<b>Number Desired Of Reviews:</b> 
						<input type="text" name="desired_reviews" value=<%=app.getNumDesiredReviews()%> class="txtbox" disabled="true"/>
						</td>

						<td>
			 			<b>Tier:</b> 
						<input type="text" name="tier" value=<%=app.getTier()%> class="txtbox" disabled="true"/>
						</td>
						
						<td><b>Application Average Rating:</b> 
						<input type="text" name="avg_rating" value=<%=app.getAvgRating()%> class="txtbox" disabled="true"/>
						</td>
					</tr>

					<tr>
						<td><b>Application Summary:</b></td>
						
						<td><b>TOEFL Comments:</b></td>
					</tr>

					<tr>
						<td>
						<textarea name="text_summary" rows="5" cols="50" disabled="true"> <%=app.getSummary()%> </textarea>
						</td>
						
						<td>
						<textarea name="text_comment" rows="5" cols="50" disabled="true"> <%=app.getToeflComments()%> </textarea>
						</td>
					</tr>	
				</table>
				
					<!-- Display an edit and update button only if user is a chair -->
					<%
						if (user.getType().equals("Chair")) {
					%>
					<label>Enable Editing:</label> <input type="checkbox" value="ON" name=edit_chkBox onclick="enableFields()">
					
					<input type="submit" value="Update" name=update class="btn" disabled="true">
					<%
						}
					%>
				<br/>
					<hr/>
				</form>	
		</div>
			
		<!-- Represents basic information from the reviewer -->
			
			<div id="reviewer">
				<h3>
					<u>Reviews For Application</u>
				</h3>
					<table border="1" width="900" cellpadding="3" cellspacing="3">
						
						<!-- Headers -->
						<tr>
							<th>Reviewer</th>
							<th>Review Date</th>
							<th>Rating</th>
							<th>Review</th>
						</tr>
						
						<!-- Review Stuff -->
						<tr align="center">
							<td><%=app.getReviewer1()%></td>
							<td><% if (app.getReviewDate1() != null) {%><%=app.getReviewDate1()%><% } %></td>
							<td><% if (app.getRating1() != 0) { %><%=app.getRating1()%><% } %></td>
							<td><ul><% if (app.getReview1() != null ) { %><%=app.getReview1()%><% } %></ul></td>
						</tr>	
							<tr align="center">
							<td><%=app.getReviewer2()%></td>
							<td><% if (app.getReviewDate2() != null) %><%=app.getReviewDate2()%></td>
							<td><% if (app.getRating2() != 0) %><%=app.getRating2()%></td>
							<td><ul><% if (app.getReview2() != null) %><%=app.getReview2()%></ul></td>
						</tr>	
						
						<tr>	
							<tr align="center">
							<td><%=app.getReviewer3()%></td>
							<td><% if (app.getReviewDate3() != null)%><%=app.getReviewDate3()%></td>
							<td><% if (app.getRating3() != 0) %><%=app.getRating3()%></td>
							<td><ul><% if (app.getReview3() != null) %><%=app.getReview3()%></ul></td>
							</tr>	
							<tr align="center">
							<td><%=app.getReviewer4()%></td>
							<td><% if (app.getReviewDate4() != null)%><%=app.getReviewDate4()%></td>
							<td><% if (app.getRating4() != 0) %><%=app.getRating4()%></td>
							<td><ul><% if (app.getReview4() != null) %><%=app.getReview4()%></ul></td>
						</tr>
						<tr>	
							<tr align="center">
							<td><%=app.getReviewer5()%></td>
							<td><% if (app.getReviewDate5() != null)%><%=app.getReviewDate5()%></td>
							<td><% if (app.getRating5() != 0) %><%=app.getRating5()%></td>
							<td><ul><% if (app.getReview5() != null) %><%=app.getReview5()%></ul></td>
						</tr>
					</table>
			</div>
					
				<div id="bottom_buttons">
					<br/>
						<hr/>
								<center>
								<form name="return" action="viewApps.jsp" method="get">					
								<!-- Returns to the previous page, which would be the view table page.-->
								<input type="submit" value="Finished Viewing" class="btn">
								</form>	
								<br/>
								
								<% 
								for(int i = 0; i < user.getReviewsNeeded().size(); i++) {
									System.out.println("reviews" + user.getReviewsNeeded().get(i) + "application id:" + app.getAppId());
									if(Integer.parseInt(app.getAppId()) == user.getReviewsNeeded().get(i)) {
										// get the review
										if(review == null) { %>
											<form name="return" action="ReviewApp.do" method="post">				
												<span><strong>Rating: </strong></span><br/><input type="text" name="ratingTxt" value=""/><br/>
												<span><strong>Summary: </strong></span><br/><textarea name="summaryTxt" rows="4" cols="50"></textarea><br/>
												<input type="submit" value="Submit New Review" class="btn">
											</form>
										<%}

									}
								}
								%>
								
								<% 
								if(review != null) {  %>
								<form name="return" action="UpdateReviewApp.do" method="post">	
									<span><strong>Rating: </strong></span> <br/><input type="text" name="ratingTxt" value="<%=review.getRating()%>"/><br/>
									<span><strong>Summary: </strong></span><br/> <textarea name="summaryTxt" rows="4" cols="50"><%=review.getReview()%></textarea><br/>			
									<input type="submit" value="Update Review" class="btn">
								</form>
							<%
						} %>
								
								
								</center>
				</div>
		</div>
	</div>
</body>
</html>